package com.xiaocg.singleton;

import java.io.Serializable;

/**
 * 单例模式 -- 饿汉模式
 * 直接new 或者 通过静态代码块 初始化对象
 */
public class Singleton implements Serializable {

    private static Singleton singleton = new Singleton();

    private static Singleton singleton1;

    static {
        singleton1 = new Singleton();
    }

    private Singleton(){}

    public static Singleton getInstance(){
        return singleton;
    }

    public static Singleton getInstance1(){
        return singleton1;
    }

    /**
     * 添加readResolve 方法，当调用反序列化
     */
    public Object readResolve(){
        return singleton1;
    }
}
